//
//  BaseTabBarVC.swift
//  手账
//
//  Created by zhuxiaoxiang on 2018/11/25.
//  Copyright © 2018年 zhuxiaoxiang. All rights reserved.
//

import UIKit

class BaseTabBarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setUpChildControllers()
    }

}

extension BaseTabBarVC {
    fileprivate func setUpChildControllers() {
        self.tabBar.isTranslucent = false
        self.tabBar.tintColor = UIColor.hex(hexString: "728CFF")
        addChildController(MainViewController(), title: "首页", imageName: "home", hasNav: true)
        addChildController(BookViewController(), title: "账本", imageName: "book", hasNav: true)
        addChildController(MineViewController(), title: "我的", imageName: "mine", hasNav: false)
    }
    
    fileprivate func addChildController(_ childVC: UIViewController, title: String, imageName: String, hasNav: Bool) {
        childVC.title = title
        childVC.tabBarItem.image = UIImage(named: imageName)
        childVC.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        if hasNav {
            let childNav = XXNavigationController(rootViewController: childVC)
            addChildViewController(childNav)
        }else {
            addChildViewController(childVC)
        }
    }
}
